package Job;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * description:线程池定时
 * author:zcx
 * lenovo
 * 时间：2022.02.08.10.53
 */
public class Job1 {
    public static void main(String[] args) throws ParseException {
    var s=new ScheduledThreadPoolExecutor(1);
    //在指定时间开始2022-02-08 11:05:01
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long init =sdf.parse("2022-02-08 11:06:01").getTime()-System.currentTimeMillis();
//        s.schedule(()->{
//            System.out.printf("%tF %<tT%n",System.currentTimeMillis());
//            s.shutdown();
//        },init,TimeUnit.MILLISECONDS);
        s.scheduleAtFixedRate(()->{
            System.out.printf("%tF %<tT%n",System.currentTimeMillis());
        },init,5000L,TimeUnit.MILLISECONDS);
    }
    public static void ses(String[] args) {
        ScheduledExecutorService ses=new ScheduledThreadPoolExecutor(1);
        ses.schedule(()->{
            System.out.println("hello world222");
        },1, TimeUnit.SECONDS);
        ses.scheduleAtFixedRate(()->{
            System.out.println("hello world222");
        },5,1,TimeUnit.SECONDS);
    }
    public static void timer(String[] args) {
        var t=new Timer();
        t.schedule(new TimerTask(){
            @Override
            public void run(){
                System.out.println("hello world");
            }
        },3000,1000);
        System.out.println("ooo");
    }
}
